// components/lifetimes/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    num: 1,
    rgbcolor: "rgb(0,0,0)"
  },

  /**
   * 组件的方法列表
   */
  methods: {

    setNum() {
      console.log(a.b.c);
    }

  },
  // 生命周期:lifetimes对象包着
  lifetimes: {
    created() {
      // this.setData({
      //   num: this.data.num + 1
      // })
      // console.log(this.data.num);
      console.log('created');
    },
    attached() {
      console.log('attached');
      this.setData({
        num: this.data.num + 1
      })
    },
    ready() {
      console.log('ready');
    },
    moved() {
      console.log('moved');
    },
    error(err) {
      console.log('error', err);
    },
    detached() {
      console.log('detached');
    }
  },
  // 组件所在页面生命周期回调
  pageLifetimes: {
    show() {
      console.log('显示时');
      this.setData({
        rgbcolor: `rgb(${Math.floor(Math.random()*256)},${Math.floor(Math.random()*256)},${Math.floor(Math.random()*256)})`
      })

    },
    hide() {
      console.log('隐藏时');
    },
    resize() {
      console.log('resize');
    }

  }
})